$(function(){ 
	$("#"+tabId+" #search_png").click(function(){
		getDataTable();
	});
	$.post(contextPath + "/LoginInfo/getLastestIssue.dhc").done(function(result) {
		if(result.success && result.data){
			var date = result.data.fromDate;
			var arr = date.split('-');
			$("#"+tabId+" input#edate").val(date);
			$("#"+tabId+" input#sdate").val(arr[0] +"-"+ arr[1] +"-01");
			getDataTable();
	  }
	});
}); 
//绘制datatables表格，该表格为用户信息表格
function getDataTable(){
	var from = $("#"+tabId+" input#sdate").val();
	var to = $("#"+tabId+" input#edate").val();
	var tb_id='tb'+new Date().getTime();
	$("#"+tabId+ " #login-detail").html('<table class="stripe cc table"  id="'+tb_id+'"'
			+'style="text-align: center;">'
			+'<thead><tr>'
			+'<td width="120">登录人账号</td>'
			+'<td width="100">登录人用户名</td>'
			+'<td width="100">登录次数</td>'
			+'<td width="140">最近一次登录时间</td>'
			+'<td width="140">最近一次登录IP(主机)</td>'
			+'</tr></thead><tbody></tbody></table>');
	
	var tdata =null;
	$.post(contextPath+'/LoginInfo/getLoginInfo.dhc',{
		'fromDate':from,
		'toDate':to
	}).done(function(result){
 		if(result!=null){
 		  	tdata=result.data;
 		  	var columns=[ {
				"data" : "loginUserCode",
				"orderable":true,
				"type":"chinese-string"
			}, {
				"data" : "loginUserName",
				"orderable":true
			}, {
				"data" : "loginCount_1",
				"orderable":true,
				"type":"number-html",
				"render": function(obj, type, full){
					return "<a title=\"查看历史登录记录\" href=\"javascript:getLoginHistory('"+full.loginUserCode+"', '"+from+"', '"+to+"')\">"+full.loginCount+"</a>"
				}
				
			}, {
				"data" : "newLoginTime",
				"orderable":true
			}, {
				"data" : "newLoginIP",
				"orderable":false
			} ];
 		  	var paramsDataTables={stateSave:true,rownumbers:true,pageLength:50,order:[[ 3, "desc" ]]};
 		  	$("#"+tabId+" #"  + tb_id).dataTableBasic(columns,tdata,paramsDataTables);
 		}
	});
}
function getLoginHistory(userCode, dateFrom, dateTo){
	$.post(contextPath + "/pages/common/top-dialog.jsp").done(function(data){
		var dialog = $(data);
		dialog.find(".modal-title").html("历史登录记录查询");
		dialog.modal({
			"keyboard": false
		}).on({
			"hidden.bs.modal": function(){
				$(this).remove();
			},
			"shown.bs.modal": function(){
				$.post(contextPath + "/LoginInfo/getLoginHistory.dhc",
						{
							"userCode": userCode,
							"dateFrom": dateFrom,
							"dateTo": dateTo
						}
				).done(function(result){
					dialog.find(".echartscq").html('<table class="stripe cc table szylogin"'
							+'style="text-align: center;transition:all .2s;">'
							+'<thead><tr>'
							+'<td width="120">登录帐号</td>'
							+'<td width="100">用户名</td>'
							+'<td width="140">登录时间</td>'
							+'<td width="140">登录IP(主机)</td>'
							+'</tr></thead><tbody></tbody></table>');
					var columns=[ {
						"data" : "loginUserCode"
					}, {
						"data" : "loginUserName"
					}, {
						"data" : "loginTime"
					}, {
						"data" : "loginIP"
					} ];
					var paramsDataTables={lengthChange:false,searching:false,pageLength:50,order:[[ 2, "desc" ]]};
					dialog.find(" .szylogin").dataTableBasic(columns,result.data,paramsDataTables);
				})
			}
		})
	})
}
